package cn.tedu.sp03.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import cn.tedu.pojo.User;
import cn.tedu.service.UserService;
import cn.tedu.web.util.JsonResult;

@RestController
public class UserController {
	@Autowired
	private UserService userService;
	
	@GetMapping("/{userId}")
	public JsonResult<User> getUser(@PathVariable Integer userId){
//		try {
//			System.out.println("延迟了~~");
//			Thread.sleep(1000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		User user = userService.getUser(userId);
		return JsonResult.ok(user);
	}
	@GetMapping("/{userId}/score")
	public JsonResult addScore(@PathVariable Integer userId,Integer score) {
		userService.addScore(userId, score);
		return JsonResult.ok();
	}
}
